package com.hnichr.ump.common.controller;

import com.hnichr.ump.common.service.MinioService;
import com.hnichr.ump.common.vo.UploadVO;
import com.mxpioframework.common.vo.Result;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

@RestController
@RequestMapping("/common/v1/")
@Tag(name = "AdminUploadController", description = "管理端minIO上传接口")
public class AdminUploadController {

    @Autowired
    private MinioService minioService;

    @PostMapping("upload")
    @Operation(summary = "上传文件", description = "上传文件", method = "POST")
    public Result<UploadVO> upload(@RequestParam("file") MultipartFile[] file) {
        UploadVO vo =  minioService.upload(file);
        if(StringUtils.isNotBlank(vo.getMsg())){
            return Result.error(vo.getMsg());
        }
        return Result.OK(vo);
    }
}
